class AIManager:
    def __init__(self, capacity=10):
        self.assistants = []
        self.capacity = capacity

    def add_assistant(self, assistant, silent=False):
        if any(a.id == assistant.id for a in self.assistants):
            if not silent:
                print(f"错误：ID【{assistant.id}】已存在，无法添加。")
            return False

        if not (0 <= assistant.score <= 100):
            if not silent:
                print(f"错误：能力评分必须在0-100之间，当前值【{assistant.score}】无效。")

        if not assistant.name or not assistant.name.strip():
            if not silent:
                print("错误：助手名称不能为空。")
            return False

        valid_types = ["文本助手", "图像助手", "数据分析助手", "翻译助手", "语音助手"]
        if assistant.type not in valid_types:
            if not silent:
                print(f"错误：助手类型无效，必须是以下之一：{', '.join(valid_types)}")
            return False

        if len(self.assistants) >= self.capacity:
            if not silent:
                print("存储已满，无法添加更多AI助手。")
            return False

        self.assistants.append(assistant)
        if not silent:
            print(f"助手【{assistant.name}】添加成功！")
        return True

    def list_assistants(self):
        if not self.assistants:
            print("暂无AI助手数据。")
            return
        for i, a in enumerate(self.assistants, 1):
            print(f"{i}. {a}")

    def find_by_id(self, id):
        return next((a for a in self.assistants if a.id == id), None)

    def show_details(self, id):
        a = self.find_by_id(id)
        if a:
            print("查询结果:", a)
        else:
            print("未找到该ID对应的AI助手。")

    def modify_assistant(self, id, attr, value):
        assistant = self.find_by_id(id)
        if not assistant:
            print(f"未找到ID为【{id}】的AI助手，修改失败。")
            return
        if not hasattr(assistant, attr):
            print(f"无效属性【{attr}】，修改失败。")
            return
        if attr == "online":
            value = value in ["1", "True", "true", "是"]
        elif attr == "score":
            try:
                value = float(value)
            except ValueError:
                print("能力评分必须是数字！")
                return
        setattr(assistant, attr, value)
        print(f"助手【{assistant.name}】(ID:{id}) 的属性【{attr}】已修改为：{value}")

    def delete_assistant(self, id):
        a = self.find_by_id(id)
        if a:
            self.assistants.remove(a)
            print(f"助手【{a.name}】已删除。")
        else:
            print("未找到该助手。")

    def start_service(self, id):
        a = self.find_by_id(id)
        if not a:
            print("未找到该助手。")
            return
        a.online = True
        print(f"助手【{a.name}】已在运行。")

    def stop_service(self, id):
        a = self.find_by_id(id)
        if not a:
            print("未找到该助手。")
            return
        a.online = False
        print(f"助手【{a.name}】已停止。")

    def assign_task(self, id, task):
        a = self.find_by_id(id)
        if not a:
            print("未找到该助手。")
            return
        if not a.online:
            print(f"{a.name} 当前离线，无法执行任务。")
        else:
            print( a.perform_task(task))

    def show_statistics(self):
        total = len(self.assistants)
        online = sum(a.online for a in self.assistants)
        offline = total - online
        avg_score = (sum(a.score for a in self.assistants) / total) if total > 0 else 0
        print(f"\n系统统计信息：")
        print(f"总助手数: {total}")
        print(f"在线助手数: {online}")
        print(f"离线助手数: {offline}")
        print(f"平均能力评分: {avg_score:.2f}")
